package com.rsk.api.curriculum;


import java.text.ParseException;
import java.util.Date;

import javax.ws.rs.QueryParam;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.rsk.aop.ParamCheck;
import com.rsk.api.common.ReturnUtils;
import com.rsk.service.curriculum.RskCourseEvaluateService;
import com.rsk.utils.result.Result;
import com.rsk.utils.result.ResultBuilder;
import com.rsk.utils.result.ResultCode;
import com.rsk.utils.tools.DateUtils;
import com.rsk.utils.tools.PageUtils;

@RestController
@RequestMapping(value="/rsk/courseEvalua")
public class RskCourseEvaluateApi {
	
	@Reference(interfaceClass = RskCourseEvaluateService.class, protocol = "dubbo")
	private RskCourseEvaluateService rskCourseEvaluateService;
	
	
	//@RequiresPermissions("coursecategory:save")
	@PostMapping(value="/saveCourseEvaluate" )
	public Result<String> saveRskCourseEvaluate(
			@QueryParam("courseId") @ParamCheck(notNull=true) Long courseId,
		   	@QueryParam("comments") @ParamCheck(notNull=true) String comments,
		   	@QueryParam("commentTime") @ParamCheck(notNull=true) String commentTime,
		   	@QueryParam("commentStatus") @ParamCheck(notNull=true) Integer commentStatus,
		   	@QueryParam("commentSource") @ParamCheck(notNull=true) Integer commentSource,
		   	@QueryParam("commentUser") @ParamCheck(notNull=true) String commentUser,
		   	@QueryParam("commentPhoto") @ParamCheck(notNull=true) String commentPhoto,
		   	@QueryParam("isTop") @ParamCheck(notNull=true) Integer isTop,
		   	@RequestHeader("Authorization") String Authorization) throws ParseException{
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = rskCourseEvaluateService.saveRskCourseEvaluate(courseId, comments, DateUtils.stringToDateDefault(commentTime), commentStatus, 
				commentSource, commentUser, commentPhoto, isTop, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	
	//@RequiresPermissions("coursecategory:del")
	@PostMapping(value="/delCourseEvaluate" )
	public Result<String> delRskCourseEvaluate(@QueryParam("id") @ParamCheck(notNull=true) Long id,
									   @RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = rskCourseEvaluateService.delRskCourseEvaluate(id, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	
	//@RequiresPermissions("coursecategory:updateSee")
	@PostMapping(value="/updateCourseEvaluateStatus" )
	public Result<String> updateRskCourseEvaluateStatus(@QueryParam("id") @ParamCheck(notNull=true) Long id,
									            @QueryParam("commentStatus") @ParamCheck(notNull=true) Integer commentStatus,
									            @RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = rskCourseEvaluateService.updateRskCourseEvaluateStatus(id, commentStatus, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	
	//@RequiresPermissions("coursecategory:updateSee")
	@PostMapping(value="/updateCourseEvaluateTop" )
	public Result<String> updateRskCourseEvaluateTop(@QueryParam("id") @ParamCheck(notNull=true) Long id,
												   @QueryParam("isTop") @ParamCheck(notNull=true) Integer isTop,
												   @RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = rskCourseEvaluateService.updateRskCourseEvaluateTop(id, isTop, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	

	@SuppressWarnings("rawtypes")
	@PostMapping(value="/selectCourseEvaluateByPage" )
	public Result<PageUtils> selectRskCourseEvaluateByPage(
			@QueryParam("nowPage") @ParamCheck(notNull=true) Integer nowPage,
			@QueryParam("pageSize") @ParamCheck(notNull=true) Integer pageSize,
			@QueryParam("courseId") @ParamCheck(notNull=true) Long courseId,
			@RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		PageUtils page = rskCourseEvaluateService.selectRskCourseEvaluate(courseId, nowPage, pageSize);
		return ResultBuilder.success(page, ResultCode.SUCCESS);
	}
}
